///////////////////////////////////////////////////////////////////////////////////////////////
// This is a header file to implement Pulse Width 			///////////////////////////////////
// Modulation on the ATMega324p. It is used on the Mercury 	///////////////////////////////////
// Robot for our Senior Design Project.						///////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
/// Created by Jonathan Kropp 					 		   	///////////////////////////////////
///	Version		Date: 							 		   	///////////////////////////////////
///  V.0		4/04/2012                        		   	///////////////////////////////////
///												 		   	///////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////

//  PWM is used to control the motors. 



// Initialize PWM
void init_pwm(void){
// Set PWM pins as output
	set_output(DDRD,left_D2); 
	set_output(DDRD,right_D2); 
	
// Set on Match, Clear on TOP
	TCCR1A = ((1<<COM2A1) | (1<<COM2A0) | (1<<COM2B1) | (1<<COM2B0) | (1<<WGM21) |(1<<WGM20));
	
// Phase + Frequency Correct PWM (WGM22:20), Fcpu speed (no prescailing)
	TCCR2B = ((1<<WGM22) | (1<<CS20));
	
// Enable Outpur Compare Match Interrupts
	//TIMSK2 |= ((1<<OCIE2A));	

// Set Duty Cycle (TOP of Counter). Inverted PWM. Init to 0% duty cycle.
	OCR2A = 0xFF;
	OCR2B = 0xFF;
	
	} // init_PWM
